// ==UserScript==
// @name Open-Source Alternative Redirector
// @namespace -
// @version 0.8
// @description Redirects you from proprietary web-services to ethical alternatives(front-end).
// @author NotYou
// @include *youtube.com/*
// @include *google.com/*
// @include *yahoo.com/*
// @include *bing.com/*
// @include *reddit.com/*
// @include *twitter.com/*
// @include *instagram.com/*
// @include *wikipedia.org/*
// @include *medium.com/*
// @include *i.imgur.com/*
// @include *odysee.com/*
// @include *tiktok.com/*
// @run-at document-start
// @license GPL-3.0-or-later
// @icon https://icons.iconarchive.com/icons/itweek/knob-toolbar/32/Knob-Shuffle-Off-icon.png
// @grant none
// ==/UserScript==

/*

﹀ Change Log ﹀

0.8 Version:
- Added Scribe(Medium)
- Added Rimgo(i.imgur)
- Added Librarian(Odysee)
- Added ProxiTok(TikTok)

0.7 Version:
- Removed duckduckgo
- Better instagram redirect
- Added google translate

0.6 Version:
- Redirect from yahoo
- Redirect from bing
- Redirect from duckduckgo

0.5 Version:
- Support for other languages for wikiless/wikipedia
- Better Instances format

*/

var url = new URL(window.location.href)

// INSTANCES //
const
invidious = 'yt.artemislena.eu',
searx = 'search.mdosch.de',
libreddit = 'old.reddit.com',
nitter = 'nitter.net',
bibliogram = 'bibliogram.pussthecat.org',
wikiless = 'wikiless.org',
lingva = 'lingva.ml',
scribe = 'scribe.rip',
rimgo = 'rimgo.bcow.xyz',
librarian = 'librarian.pussthecat.org',
proxitok = 'proxitok.herokuapp.com'

// YouTube | Invidious //
if(window.location.host.indexOf('youtube.com') != -1){
    window.location.replace('https://' + invidious + window.location.pathname + window.location.search)
}

if(window.location.host.indexOf('google.com') != -1){
    // Google Translate | Lingva Translate //
    if(window.location.host.indexOf('translate.google.com') != -1){
        if(window.location.search === '') {
            window.location.replace('https://' + lingva)
        } else {
            let lang1 = window.location.search.split('&')[0].split('=')[1];
            let lang2 = window.location.search.split('&')[1].split('=')[1];
            let text = window.location.search.split('&')[2].split('=')[1];
            window.location.replace('https://' + lingva + '/' + lang1 + '/' + lang2 + '/' + text)
        }
    // Google | SearX //
    } else if(window.location.host.indexOf('google.com') != -1) {
        window.location.replace('https://' + searx + window.location.pathname + window.location.search)
    }
}

// Yahoo | SearX //
if(window.location.host.indexOf('yahoo.com') != -1){
    let search = window.location.search.replace('?p', '?q')
    window.location.replace('https://' + searx + window.location.pathname + search)
}

// Bing | SearX //
if(window.location.host.indexOf('bing.com') != -1){
    window.location.replace('https://' + searx + window.location.pathname + window.location.search)
}

// Reddit | Libreddit //
if(window.location.host.indexOf('reddit.com') != -1){
    window.location.replace('https://' + libreddit + window.location.pathname + window.location.search)
}

// Twitter | Nitter //
if(window.location.host.indexOf('twitter.com') != -1){
    window.location.replace('https://' + nitter + window.location.pathname + window.location.search)
}

// Instagram | Bibliogram //
if(window.location.host.indexOf('instagram.com') != -1){
    if(window.location.pathname === '/accounts/login/') {
        let path1 = window.location.search.split('?next=').at(1)
        let path = '/u' + path1
        window.location.replace('https://' + bibliogram + path)
    } else {
        window.location.replace('https://' + bibliogram + window.location.pathname + window.location.search)
    }
}

// Wikipedia | Wikiless //
if(window.location.host.indexOf('wikipedia.org') != -1){
    let sub = url.hostname.split('.')[0];
    window.location.replace('https://' + wikiless + window.location.pathname + '?lang=' + sub)
}

// Medium | Scribe //
if(window.location.host.indexOf('medium.com') != -1){
    window.location.replace('https://' + scribe + window.location.pathname + window.location.search)
}

// i.Imgur | Rimgo //
if(window.location.host.indexOf('i.imgur.com') != -1){
    window.location.replace('https://' + rimgo + window.location.pathname + window.location.search)
}

// Odysee | Librarinan //
if(window.location.host.indexOf('odysee.com') != -1){
    window.location.replace('https://' + librarian + window.location.pathname + window.location.search)
}

// TikTok | ProxiTok //
if(window.location.host.indexOf('tiktok.com') != -1||window.location.host.indexOf('www.tiktok.com') != -1){
    window.location.replace('https://' + proxitok + window.location.pathname + window.location.search)
}
























